/**
 * 
 */
package com.zhangjihao.utils;

import java.time.LocalDate;
import java.time.Period;
import java.util.Calendar;
import java.util.Date;

/**
 * 说明：
 * 
 * @author  zhangjihao(mailto:zhangjihao@sohu.com)
 * @version v1.0 <br>
 * 创建于：2020年4月23日 下午4:53:28
 */
public class DateUtil {

	private DateUtil(){}
	
	/**
	 * 功能：根据生日求年龄 <br>
	 * 示例：现在是2020-4-23，如果生日是2020-5-20，那结果是19 <br><br>
	 *
	 * @param birthday
	 * @return 年龄
	 */
	public static int getAge(Date birthday){
		
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(birthday);
		
		//生日
		LocalDate birthdayLocalDate = LocalDate.of(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH));
		//今天
		LocalDate now = LocalDate.now();	
		//Java8的日期差计算工具
		Period period = Period.between(birthdayLocalDate, now);
		
		int result = period.getYears();
		
		return result;
		
	}
	
	
	/**
	 * 功能：获取当前季节
	 *
	 * @return Season
	 */
	public static Season getCurrentSeason(){
		Calendar today = Calendar.getInstance();
		int month = today.get(Calendar.MONTH) + 1;
		
		if(month < 7){
			if(month <=3 ){
				return Season.SPRING;
			}
			else{
				return Season.SUMMER;
			}
		}else{
			if(month <= 9 ){
				return Season.AUTUMN;
			}
			else{
				return Season.WINTER;
			}
		}
		
	}
	
	
	/**
	 * 说明：季节枚举<br>
	 * 
	 * @author  zhangjihao(mailto:zhangjihao@sohu.com)
	 * @version v1.0
	 * 创建于：2020年4月24日 下午2:18:29
	 */
	public enum Season{
		SPRING,SUMMER,AUTUMN,WINTER
	}
	
}
